package com.hzg.action;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.hzg.annotation.ActionAnnotation;
import com.hzg.annotation.ForwardAnnotation;

public class LoginAction implements BaseAction {

	@ActionAnnotation(method = "reg", formClass = "com.hzg.action.User",
			forwards = {@ForwardAnnotation(name = "success", url = "view/LoginSucess.jsp"), @ForwardAnnotation(name = "fail", url = "view/LoginFaild.jsp")})
	public String execute(HttpServletRequest request, User user, Map<String, String> actionForward) {
		System.out.println("execute");
		String result ="fail";
		String forwardUrl =null;
		forwardUrl = actionForward.get(result);
		User user2 = (User) user;
		if(user2.getUsername().equals("admin")&&user2.getPassword().equals("admin")){
			result ="success";
			forwardUrl = actionForward.get(result);
		}
		return forwardUrl;
	}
	
	@ActionAnnotation(method = "login", formClass = "com.hzg.action.User",
			forwards = {@ForwardAnnotation(name = "success", url = "view/LoginSucess.jsp"), @ForwardAnnotation(name = "fail", url = "view/LoginFaild.jsp")})
	public String login(HttpServletRequest request, User user, Map<String, String> actionForward) {
		System.out.println("login!");
		String result ="fail";
		String forwardUrl =null;
		forwardUrl = actionForward.get(result);
		User user2 = (User) user;
		if(user2.getUsername().equals("admin")&&user2.getPassword().equals("admin")){
			result ="success";
			forwardUrl = actionForward.get(result);
			
		}
		return forwardUrl;
	}
}
